﻿using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Win32;
using System.Windows;
using TiaoTiaoCode.DesignLangTranstlateTool.ViewModels;

namespace TiaoTiaoCode.DesignLangTranstlateTool
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainViewModel ViewModel => (MainViewModel)DataContext;

        public MainWindow()
        {
            InitializeComponent();

            DataContext = Ioc.Default.GetRequiredService<MainViewModel>();
        }

        private void BtnLoadClick(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                Filter = "设计时语言文件|*.xaml"
            };

            var b = ofd.ShowDialog();
            if (b == null || !(bool)b) return;
            
            ViewModel.LoadCommand.Execute(ofd.FileName);
        }

        private void BtnSaveClick(object sender, RoutedEventArgs e)
        {
            var sfd = new SaveFileDialog
            {
                Filter = "语言文件|*.json"
            };

            var b = sfd.ShowDialog();
            if (b == null || !(bool)b) return;

            ViewModel.SaveCommand.Execute(sfd.FileName);
        }
    }
}
